package com.sgb.kjwl.view.ui.activity.enterprise;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySignupSuccessNoticeBinding;
import com.sgb.kjwl.model.entity.enterprise.MyNeedQuoteDatailEntity;
import com.sgb.kjwl.viewmodel.enterprise.SignUpSuccessNoticeViewModel;

public class SignUpSuccessNoticeActivity extends AppActivity {
    private ActivitySignupSuccessNoticeBinding mBinding;
    private SignUpSuccessNoticeViewModel mViewModel;


    @Override
    protected void initView() {
        super.initView();
        mViewModel = new ViewModelProvider(this).get(SignUpSuccessNoticeViewModel.class);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_signup_success_notice);
        mBinding.setLifecycleOwner(this);
        MyNeedQuoteDatailEntity entity = (MyNeedQuoteDatailEntity) getIntent().getSerializableExtra("data");
        if (entity != null) {
            mBinding.tvElectionShow.setText(entity.getElectionShow());

            if (!TextUtils.isEmpty(entity.getAttachmentUrl()) && !entity.getAttachmentUrl().equals("{}")) {
                mBinding.linCode.setVisibility(View.VISIBLE);
                if (entity.getAttachmentUrl().indexOf("{") > -1) {

                    JSONObject jsonObject = JSONObject.parseObject(entity.getAttachmentUrl());
                    if (null != jsonObject.get("name")) {
                        String name = jsonObject.getString("name");
                        mBinding.tvName.setText(name);
                    }
                    if (null != jsonObject.get("size")) {
                        mBinding.tvSize.setText(jsonObject.getString("size"));
                    }
                    if (jsonObject.get("type") != null) {
                        String fileType = jsonObject.getString("type");

                        switch (fileType) {
                            case "application/zip":
                            case "application/rar":
                                Glide.with(this).load(R.mipmap.icon_zip).into(mBinding.image);
                                break;
                            case "image/png":
                            case "image/jpeg":
                                Glide.with(this).load(R.mipmap.icon_image).into(mBinding.image);
                                break;
                            case "application/pdf":
                                Glide.with(this).load(R.mipmap.icon_pdf2).into(mBinding.image);
                                break;
                        }
                    }
                }
            } else {
                mBinding.linCode.setVisibility(View.GONE);
            }
        }
    }

    public static void start(Context mContext, MyNeedQuoteDatailEntity entity) {
        Intent mIntent = new Intent();
        mIntent.setClass(mContext, SignUpSuccessNoticeActivity.class);
        mIntent.putExtra("data", entity);
        mContext.startActivity(mIntent);
    }
}
